﻿namespace Lilium

module Quotations =
    
    open System.Linq.Expressions
    open Microsoft.FSharp.Quotations
    open Microsoft.FSharp.Reflection

    let test () =
        
        let d = <@ fun (x,y) -> x + y @>
        let k = <@ fun () () -> 10 @>
        ()

    let toExpr (expression : Expression) =
        match expression.NodeType with
        | ExpressionType.Lambda -> 
            let lambda = expression :?> LambdaExpression
            let parameter = match lambda.Parameters.Count with
                            | 0 -> Var ("unitVar", typeof<Microsoft.FSharp.Core.Unit>)
                            | _ -> let parameterTypes = lambda.Parameters |> Seq.map (fun p -> p.Type) |> Seq.toArray
                                   Var ("tupledArg", FSharpType.MakeTupleType(parameterTypes))
            Expr.Lambda(parameter, 

            failwith ""
        | _ -> failwith (sprintf "Can't convert %O to F# expression" expression.NodeType)
        ()